package com.zjd.controller.servlet;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.github.pagehelper.PageInfo;
import com.zjd.domain.Route;
import com.zjd.service.RouteService;
import com.zjd.service.impl.RouteServiceImpl;
import com.zjd.utils.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/RouteServlet")
public class RouteServlet extends BaseServlet {
    private RouteService service = new RouteServiceImpl();

    public void selectRouteByPage() throws ServletException, IOException {
        String spageNum = request.getParameter("pageNum");
        String spageSize = request.getParameter("pageSize");
        String cid = request.getParameter("cid");
        int pageNum = 1;
        int pageSize = 5;
        if (spageNum != null && spageNum != "" && spageNum != "0") {
            pageNum = Integer.valueOf(spageNum);
        }
        if (spageSize != null && spageSize != "" && spageSize != "0") {
            pageSize = Integer.valueOf(spageSize);
        }
        PageInfo<Route> pageInfo = service.selectRouteByPage(pageNum, pageSize, Integer.valueOf(cid));
        writeJson(response,pageInfo);
    }

}